const { Router } = require('express');

const { validateBody, validateQuery } = require('../middleware/validation');
const {
  createDocumentSchema,
  updateDocumentSchema,
  listDocumentsQuerySchema,
  searchDocumentsQuerySchema,
  searchDocumentsVectorSchema,
  updateVectorSchema
} = require('../schemas/doc.schema');
const { docsController } = require('../controllers/docs.controller');

function createDocsRouter() {
  const router = Router();

  router.get('/', validateQuery(listDocumentsQuerySchema), docsController.list);
  router.post('/', validateBody(createDocumentSchema), docsController.create);

  router.get('/search', validateQuery(searchDocumentsQuerySchema), docsController.searchByText);
  router.post('/search', validateBody(searchDocumentsVectorSchema), docsController.searchByVector);

  router.get('/:id', docsController.getById);
  router.put('/:id', validateBody(updateDocumentSchema), docsController.update);
  router.delete('/:id', docsController.remove);
  router.post('/:id/vector', validateBody(updateVectorSchema), docsController.updateVector);

  return router;
}

module.exports = { createDocsRouter };
